﻿using System.IO;
using HybridCLR.Editor.AOT;
using UnityEditor;
using UnityEngine;

namespace HybridCLR.Editor
{
    public class AutoCompileHybridCLRDll
    {
        /// 进一步剔除AOT dll中非泛型函数元数据，输出到.dll.r
        [MenuItem("HybridCLR/Generate/AOTDlls Strip", priority = 106)]
        public static void StripAOTAssembly()
        {
            if(!SettingsUtil.Enable)
                return;
            BuildTarget target = EditorUserBuildSettings.activeBuildTarget;
            string srcDir = SettingsUtil.GetAssembliesPostIl2CppStripDir(target);
            foreach (var src in Directory.GetFiles(srcDir, "*.dll"))
            {
                AOTAssemblyMetadataStripper.Strip(src, src+".r");
            }
        }
        [UnityEditor.Callbacks.DidReloadScripts]
        public static void CompileHotfixDll()
        {
            if(!SettingsUtil.Enable)
                return;
            HybridCLR.Editor.Commands.CompileDllCommand.CompileDllActiveBuildTargetDevelopment();
            Debug.Log("Auto Compile HybridCLR DLL !!!");   
        }
    }
}